package com.gilight.base.controller;

import com.gilight.base.admin.freight.AdminFreightTemplateService;
import com.gilight.base.admin.search.AdminSearchService;
import com.gilight.base.base.ResultEntity;
import com.gilight.base.base.exception.ServiceException;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author liken
 * 商品管理控制类
 */
@RestController
@RequestMapping("/web/admin-search")
public class AdminSearchController {

    @Autowired
    private AdminSearchService adminSearchService;


    @ApiOperation(value = "初始化")
    @RequestMapping(value = "/init")
    public ResultEntity init(Long adminId) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminSearchService.init(adminId));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }


    /**
     * 创建1
     * @return
     */
    @ApiOperation(value = "重建商品")
    @RequestMapping(value = "/rebuild")
    public ResultEntity rebuild(
            Long adminId) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminSearchService.rebuild(adminId));
        } catch (ServiceException e) {
            e.printStackTrace();
        };
        return resultEntity;
    }




    @ApiOperation(value = "重新加载配置")
    @RequestMapping(value = "/reload-properties")
    public ResultEntity reloadProperties(
            Long adminId) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminSearchService.reloadProperties(adminId));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }

}
